<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <input type="button" id="btn" value="点击"><br>
    <img src="images/a.jpg"  id="pic">
    <script>
        var btn = document.getElementById("btn");
        var pic = document.getElementById("pic");
        var num = 1;
        btn.onclick = function (){
            if (num === 1){
            pic.src = "images/b.jpg";
            num = 2;
            }else{
            pic.src = "images/a.jpg";  
            num = 1;
            }
        };
    </script>   
</body>
</html>